package com.hh.test.convert;

public class ScaleConvert {

	public static void main(String[] args) {
		System.out.println(decToBin(100001));
		System.out.println(Integer.toBinaryString(34));
		System.out.println(binToDec("100000"));
		System.out.println(binToDec("100110"));

	}

	public static String decToBin(long num) {
		String re = "";
		for (int i = 31; i >= 0; i--) {
			re += num >>> i & 1;
		}
		// System.out.println("");
		return re.replaceFirst("^0*", "");
	}

	public static long binToDec(String num) {
		long re = 0;
		int scale = num.length();
		for (int i = 0; i < scale; i++) {
			if (i == 0 && Integer.valueOf(num.substring(scale - i - 1, scale - i)) == 0) {
				continue;
			}
			// System.out.print(num.substring(scale - i - 1, scale - i)+"-");
			long d = new Double(Math.pow(2 * (Integer.valueOf(num.substring(scale - i - 1, scale - i))), i)).intValue();
			// System.out.println(d);
			re += d;
		}
		return re;
	}

}
